﻿@model Tags
@{
    // get conf
    var configObj= Model.GetConfigObject<TagsConfigObject>();
    
    // add js/css
    Html.AddToBackEndContent("~/Areas/ProggyCore/Content/Scripts/Proggy.CorePropertyTypes.js", BackEndContentType.JavaScript);
    Html.AddToBackEndContent("~/Areas/ProggyCore/Content/ThirdParty/jquery.tag-it/js/tag-it.js", BackEndContentType.JavaScript);
    Html.AddToBackEndContent("~/Areas/ProggyCore/Content/Scripts/Proggy.CorePropertyTypes.Tags.js", BackEndContentType.JavaScript);

    Html.AddToBackEndContent("~/Areas/ProggyCore/Content/ThirdParty/jquery.tag-it/css/jquery.tagit.css", BackEndContentType.Stylesheet);
    Html.AddToBackEndContent("~/Areas/ProggyCore/Content/Css/Tags.css", BackEndContentType.Stylesheet);

    Html.RenderBackEndContentForLightboxPartial();

    // get unique id
    var unique = Model.GetUniqueElementId("tags", "tags");
    var uniqueUl = Model.GetUniqueElementId("tagUl", "tagUl");
    var uniqueHidden = Model.GetUniqueElementId("tagHidden", "tagHidden");
    var formInputName = Model.PropertyNameStart + ".AppliedTags";
}
<div class="tags" id="@unique">
@if (configObj.TypeOfTagging == TaggingType.LockedListSuggestFromRandomData || configObj.TypeOfTagging == TaggingType.FreeTextSuggestFromPublishedContent) { 
    <script type="text/javascript">
        
        // create available
        var jsonObj = '@Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(Model.AllowedTags))';
        jQuery(window).data("@(unique)_locked_tag_data", jQuery.parseJSON(jsonObj));
                
    </script>
}
    @*@Html.TextArea(Model.PropertyNameStart + ".AppliedTagsCommaSep", Model.AppliedTagsCommaSep, new { @class = "proggy-textarea proggy-textarea-large" })*@
    <ul id="@uniqueUl">
        @if (Model.AppliedTags != null)
        {
            foreach (var tag in Model.AppliedTags)
            { 
            <li>
                @tag
            </li>
            }
        }
    </ul>
    <div id="@uniqueHidden">
    </div>
</div>
<script type="text/javascript">

    Proggy.Static.WaitForTypesToRegister(function () {

        // get Object
        var tagsObj = new Proggy.CorePropertyTypes.Tags();

        // init
        tagsObj.Init("@unique", "@uniqueUl", "@uniqueHidden", "@formInputName");

    });
</script>
